#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration) {
        int n = timeSeries.size();
        int sum = 0;
        for (int i = 1; i < n; i++)
        {
            if (timeSeries[i] - timeSeries[i - 1] < duration)
            {
                sum += timeSeries[i] - timeSeries[i - 1];
            }
            else
            {
                sum += duration;
            }
        }
        return sum + duration;
    }
};